<template>
  <div class="h-full" v-bind="$attrs">
    <a-button @click="handleEdit"> {{ label }}</a-button>
  </div>
  <BasicModal
    v-bind="$attrs"
    destroyOnClose
    @register="register"
    showFooter
    :title="label"
    width="60%"
    @height-change="handleHeightChange"
    @ok="handleSubmit"
  >
    <HZOffice />
  </BasicModal>
</template>
<script lang="ts" setup name="ButtonZOffice">
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';

  import HZOffice from './index.vue';

  defineProps({
    label: {
      type: String,
      default: '在线编辑',
    },
    readonly: { type: Boolean },
  });

  const emit = defineEmits(['change', 'update:value', 'format-error', 'register']);
  const height = ref('764px');

  const currentValue = ref<any>('');
  const [register, { setModalProps, closeModal }] = useModalInner();
  const handleEdit = () => {
    setModalProps({ open: true, defaultFullscreen: true });
  };

  function handleSubmit() {
    emit('update:value', currentValue.value);
    emit('change', currentValue.value);
    closeModal();
  }

  function handleHeightChange(v) {
    if (parseFloat(height.value) === v) return;

    height.value = v + 'px';
  }
</script>
<style lang="less" scoped></style>
